package com.ayu.scalalearn.chapter07

/**
  * @Author 徐林玉
  * @Description Test07ImmutableMap
  * @Date 2022/8/3 17:18
  * @Version 1.0
  */
object Test07ImmutableMap {

  def main(args: Array[String]): Unit = {


    //1、创建map
    val map1: Map[String, Int] = Map("a" -> 10, "b" -> 11, "c" -> 12)

    println(map1)
    println(map1.getClass)

    println("===========================")

    //2、遍历元素
    map1.foreach(println)

    map1.foreach(kv => println(kv))


    //3、取map中的所有的key或者value

    map1.foreach(elem => {

      println("keyset:" + elem._2)
    })



    //4、访问某个key的value
    println("a:" + map1("a"))

    println("d:" + map1.getOrElse("d", 0))
  }

}
